package 剑指offer.Month7_07.day16;

import java.util.HashMap;

public class 最长不包含重复字符的子字符串 {
    public int lengthOfLongestSubstring (String s) {
        // write code here
        int max = 0;
        HashMap<Character,Integer> map = new HashMap<>();
        for (int left = 0,right = 0;right < s.length(); right++) {
            char key = s.charAt(right);
            if(!map.containsKey(key)){
                map.put(key,1);
            }else {
                map.put(key,map.get(key) +1);
            }
            while (map.get(key) > 1){
                map.put(s.charAt(left),map.get(s.charAt(left++)) - 1);
            }
            max = Math.max(max,right - left +1);
        }
        return max;
    }
}
